package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;
import io.renren.modules.sys.entity.SysDictionariesEntity;
import io.renren.modules.sys.service.SysDictionariesKeyService;
import io.renren.modules.sys.service.SysDictionariesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
/**
 * 数据字典
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-09-04 09:45:00
 */
@RestController
@RequestMapping("sys/sysdictionaries")
public class SysDictionariesController {
    @Autowired
    private SysDictionariesService sysDictionariesService;
    @Autowired
    private SysDictionariesKeyService sysDictionariesKeyService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysdictionaries:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysDictionariesService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 得到父亲列表数据
     */
    @RequestMapping("/getDictionariesKeyList")
    @RequiresPermissions("sys:sysdictionaries:list")
    public R getDictionariesKey(){
        return R.ok().put("list", sysDictionariesKeyService.getListAll());
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysdictionaries:info")
    public R info(@PathVariable("id") Integer id){
			SysDictionariesEntity sysDictionaries = sysDictionariesService.selectById(id);
        return R.ok().put("sysdictionaries", sysDictionaries);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysdictionaries:save")
    public R save(@RequestBody SysDictionariesEntity sysDictionaries){
			sysDictionariesService.insert(sysDictionaries);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysdictionaries:update")
    public R update(@RequestBody SysDictionariesEntity sysDictionaries){
			boolean isupdate=sysDictionariesService.updateById(sysDictionaries);
			if(isupdate){
                return   R.ok();
            }else {
                return R.error("修改失败");
            }
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysdictionaries:delete")
    public R delete(@RequestBody Integer[] ids){
			sysDictionariesService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
